#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@Time    : 24-5-24 下午15:37
@Author  : zhangweihao
@File    : tasks.py
'''
import logging
from ext.flask_marsh import ma, BaseMarshmallow
from marshmallow import fields
from model.auto_model.risk_retrieval import RiskMonitoringListModel
from model.auto_model.user import UserModel
from flask import g, session


class RiskAnalysisListSchema(ma.SQLAlchemyAutoSchema, BaseMarshmallow):
    update_time = fields.DateTime(format='%Y-%m-%d %H:%M:%S')
    sex = fields.Method('trans_sex')
    user = fields.Method('get_user')

    class Meta:
        model = RiskMonitoringListModel
    
    def trans_sex(self, obj):
        return '女' if int(obj.sex) else '男'
    
    def get_user(self, obj):
        user = g.db.session.query(UserModel).filter(UserModel.id == obj.user_id).first()
        if user:
            return user.user_no


